package org.example.com.kotlinlab.delegate.property_delegate.prop_delegate

/**
 * 把一个属性委托给另外一个属性
 */

var topLevelInt: Int = 10

class ClassWithDelegate(val anotherClassInt: Int)

class MyClass(var memberInt: Int, val anotherClassInstance: ClassWithDelegate) {
    var delegatedToMember: Int by this::memberInt
    var delegatedToTopLevel: Int by ::topLevelInt

    val delegatedToAnotherClass: Int by anotherClassInstance::anotherClassInt
}

var MyClass.extDelegated: Int by ::topLevelInt

/**
 * 案例
 */

class MyCase {
    var newName: Int = 0

    @Deprecated("Use 'newName' instead", ReplaceWith("newName"))
    var oldName: Int by this::newName

    var a:Int = 0
    var b:Int = a
}

fun main() {
    val myCase = MyCase()
    myCase.newName = 42
    println(myCase.oldName)
}